The XCMD Adapter Scripting Addition allows you to use XCMD/XFCN as Scripting Additions. This is an experimental version and has not been tested. However most of the code comes from the AEXCMDShell program which has been in use for some time.
To call the XCMD, the Scripting Addition must be first loaded, then the XCMD, so this is not the most efficient way to do thing. However this gives you a quick and dirty shortcut to access a lot of the functions from AppleScript.
Not all XCMD callbacks are implemented. Try each individual XCMD to see if it works. The XCMD parameters need to follow the convention that parameters are by position and empty strings means missing optional parameter. In general, if the XCMD can work in AEXCMDShell, then it can be used as an Scripting Addition unless it needs to use the GetGlobal, SetGlobal or SendHCEvents callbacks. Furthermore, since most XCMD are written before system 7 and therefore do not to call AEInteractWithUser even when it is necessary, this may introduce inappropriate layer switching.
Since this is a prototype meant for the developer, we shall assume that you can use ResEdit and Aete Editor to edit the resource. We shall assume that you will use ResEdit to put all the XCMDs and their resource into the Scripting Addition. Then you need to edit the aete resource to tell the world about the XCMDs you have in the Scripting Addition. Each XCMD or XFCN must have a event class of ‘XCMD’. The Apple Event parameters must be in the same order as the XCMD parameters. For every XCMD you also have to generate a XINF resource which summarize the aete information for that particular XCMD. The ResEdit template is in the OSAX. The name of the XINF resource should be the same as the event ID for the XCMD. The information is mainly the keyword, dataType and delimiter for each parameter. The delimiter is “A” if the parameter is not a list. If it is a list, the delimiter is the characters that separates one item of the list from each other. Usually it is “,” or carriage return, but it can also be “|”, null or any other character you choose.
In future we shall release a new version AEXCMDShell that can generate the Scripting Addition without going through this. Look for it in AppleLink or the Developer CD.
We have included a XCMD and a XFCN as an example. The XCMD is the familiar Flash XCMD, it takes a direct parameter of type short integer. The XFCN let you determine the coordinate of a rectangle on the screen. You will use the cursor to pick the two opposite corner of a rectangle, and then a “qdrt” data type will be returned.
We also export two commands which are used internally in the Scripting Addition. They are TextToList and ListToText.
Here is an example script that let you mimic the chooser to choose your default printer .
The XCMD used are
ChoosePrinter from Chooser 1.5 by Frédéric RINALDI.
DeviceList from Chooser 1.5 by Frédéric RINALDI.
CurrPrinter from Chooser 1.5 by Frédéric RINALDI.
Sort by Gary Bond.
ShowList from HyperCard PowerTools.
The script is
copy 0 to dftprtindex
copy (DeviceList drivername "LaserWriter") to prtlist
copy (Sort prtlist) to prtlist
copy (CurrPrinter) to curprint
if first item of curprint = "LaserWriter" then
copy item 2 of curprint to curprint
copy 0 to i
repeat with x in prtlist
copy i + 1 to i
if x = curprint then
copy i to dftprtindex
end if
end repeat
end if
copy (ShowList prtlist prompt "Choose a printer" buttons {"OK", "Cancel"} hilitedline dftprtindex typingselect true multiselect false) as list to choice